package dotdashdot.bradz.trendsettr;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class ActivityItemList extends FragmentActivity implements FragmentItemList.Callbacks {
	private boolean mTwoPane;
	private ClassUberLogger logger;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_see_trend_item_list);
		logger = new ClassUberLogger("ActivityItemList");

		if (findViewById(R.id.item_detail_container) != null) {
			mTwoPane = true;
			((FragmentItemList) getSupportFragmentManager().findFragmentById(
					R.id.item_list)).setActivateOnItemClick(true);
			logger.info("Done inflating fragment");
		}
	}

	@Override
	public void onItemSelected(String id) {
		if (mTwoPane) {
			Bundle arguments = new Bundle();
			arguments.putString(FragmentItemDetail.ARG_ITEM_ID, id);
			FragmentItemDetail fragment = new FragmentItemDetail();
			fragment.setArguments(arguments);
			getSupportFragmentManager().beginTransaction()
					.replace(R.id.item_detail_container, fragment).commit();

		} else {
			Intent detailIntent = new Intent(this, ActivityItemDetail.class);
			detailIntent.putExtra(FragmentItemDetail.ARG_ITEM_ID, id);
			startActivity(detailIntent);
		}
	}
}
